﻿using AjaxControlToolkit;
using BM.Tools.WebControls.MForm.Controls.ValueHandlers;

[assembly: System.Web.UI.WebResource("BM.Tools.WebControls.MForm.Example.ValueHandlers.ZipCodeValueHandler.js", "application/x-javascript")]

namespace BM.Tools.WebControls.MForm.Example.ValueHandlers
{
    [ClientScriptResource("BM.Tools.WebControls.MForm.Example", "BM.Tools.WebControls.MForm.Example.ValueHandlers.ZipCodeValueHandler.js")]
    public class ZipCodeValueHandler : UserControlValueHandler<ZipCodeControl>
    {
        public override string Value
        {
            get
            {
                return (string.IsNullOrEmpty(Control.Prefix.Text) || string.IsNullOrEmpty(Control.Suffix.Text)) ? 
                    null : 
                    string.Concat(Control.Prefix.Text, "-", Control.Suffix.Text);
            }

            set
            {
                if (string.IsNullOrEmpty(value))
                {
                    return;
                }

                Control.Prefix.Text = value.Substring(0, 2);
                Control.Suffix.Text = value.Substring(3, 3);          
            }
        }        
    }
}
